/**
 * \file CFacturesFrm.h
 * \author Corentin Le Bail
 * \date 2009-2012
 * \brief Fichier de déclaration de la class CFacturesFrm
 */
//------------------------------------------------------------------------------
#ifndef __CFACTURESFRM_H__
#define __CFACTURESFRM_H__
//------------------------------------------------------------------------------
#include "CMyMainWindow.h"
#include "ui_CFacturesFrm.h"
#include "CGrilleWidget.h"
#include "CTextWidget.h" 
//------------------------------------------------------------------------------
/**
 * \class CFacturesFrm CFacturesFrm.h "CFacturesFrm.h"
 * \brief Classe de la fenêtre des factures.
 */
class CFacturesFrm : public CMyMainWindow, private Ui::FacturesFrm
{
	Q_OBJECT
	public:
		/**
		 * \fn CFacturesFrm(QString name, QString lastCode, QWidget *parent = 0)
		 * \brief Constructeur
		 * \param[in] name Nom de l'objet
		 * \param[in] lastCode Dernier code traité
		 * \param[in] parent Référence vers un objet parent
		 */
		CFacturesFrm(QString name, QString lastCode, QWidget *parent = 0);
		/**
		 * \fn void setNumero(int numero)
		 * \brief Affecte un numéro de facture et l'affiche
		 * \param[in] numero Numéro de la facture
		 */
		void setNumero(int numero);
	private:
		enum {cnfBl, cnfLigne, cnfArticle, cnfDescArticle, cnfQuantite, cnfUnite, cnfPrix, cnfTotal, cnfTva} EColFactNames;
		
		CGlobal::EAction actionCur;
		CGrilleWidget *lignesWidget;
		CTextWidget *commentaires;
		bool avertModifClientShown;
	
		void setActionCur(CGlobal::EAction action);
		CGlobal::EAction getActionCur(void); 
		void closeEvent(QCloseEvent * event);
		//void resizeEvent(QResizeEvent * event);
		void createGrille(void);
		void loadInfoClient(QString client);
		void loadInfoAdresse(int numeroAdresse);
		void loadGrille(void);
		void calculMontant(int ignoreRow=-1);
		void calculTotalLigne(int row);
		bool loadEnteteFromDevis(int numeroDevis);
		bool loadEnteteFromCommande(int numeroCommande);
		bool loadEnteteFromClient(QString client);
		void loadLigneFromDevis(int numeroDevis);
		void loadLigneFromCommande(int numeroCommande);
		void loadLigneFromClient(QString client);
		bool acceptDate(QDate dateFacturation);
		void factureBLs(QString listeBl, QDate dateFacturation, int& premFact, int& derFact);
		void makeRequete(QString &requete, QString &alias);
		void showFormulaire(QSqlQuery *query, CGlobal::EAction& action);
		void printMultiPage(int from, int to);
		void showChampsAuto(void);
	private slots:
		void on_actAjouter_triggered(void);
		void on_actValider_triggered(void);
		void on_actAnnuler_triggered(void);
		void on_actSupprimer_triggered(void);
		void onChange(void);
		void onChangeClient(void);
		void onCombo(CMyComboBox *comboBox);
		void onComboClient(CMyComboBox *comboBox);
		void onClientEditingFinished(void);
		void on_actRechercheUneFiche_triggered(void);
		void on_actBLsNonFacture_triggered(void);
		void ajouteLigne(bool &goToLast);
		void supprimeLigne(int row, bool& ok);
		void modifiLigne(int row, int column);
		void ligneDoubleClicked(int row, int column);
		void on_cmdAdresse_clicked(bool checked);
		void onInvokeHelp(CChamp *champ);
		void on_actPrintMultipage_triggered(void);
		void on_actLock_triggered(void);
};
//------------------------------------------------------------------------------
#endif //__CFACTURESFRM_H__
//------------------------------------------------------------------------------